import axios from "../../src/axios";

axios({
  url: "/extend/post",
  method: "post",
  data: {
    msg: "hi",
  },
});

axios("/extend/post", {
  method: "post",
  data: {
    msg: "hi 2 params",
  },
});

axios.request({
  url: "/extend/post",
  method: "post",
  data: {
    msg: "hello",
  },
});

axios.get("/extend/get");
axios.options("/extend/options");
axios.delete("/extend/delete");
axios.head("/extend/head");
axios.post("/extend/post", { data: "post" });
axios.put("/extend/put", { data: "put" });
axios.patch("/extend/patch", { data: "patch" });

interface ResponseData<T = any> {
  code: number;
  result: T;
  message: string;
}

interface User {
  name: string;
  age: number;
}

function getUser<T>(): Promise<any> {
  return axios("/extend/user")
    .then((res) => res.data)
    .catch((err) => console.error(err));
}

async function test() {
  const user = await getUser<User>();
  if (user) {
    console.log(user.result.name);
  }
}

test()
  .then((data) => console.log(data))
  .catch((err) => console.log(err));
